package org.graduation.recruitment.controller;

import org.graduation.recruitment.entity.dto.PassAndInterviewNotificationDTO;
import org.graduation.recruitment.entity.pojo.ResumeAndJob;
import org.graduation.recruitment.entity.vo.CheckResumeVO;
import org.graduation.recruitment.service.ResumeAndJobService;
import org.graduation.recruitment.service.other.InterviewNotification;
import org.graduation.recruitment.utils.ResponseResult;
import org.graduation.recruitment.utils.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/resume_and_job")
public class ResumeAndJobController {

    // 注入简历和工作服务
    @Autowired
    private ResumeAndJobService resumeAndJobService;
    // 注入面试通知服务
    @Autowired
    private InterviewNotification interviewNotification;
    // 注入Token工具类
    @Autowired
    private Token token;

    /**
     * 提交简历
     *
     * @param resumeAndJob 包含简历和应聘职位信息的对象
     * @return 提交成功返回成功结果，否则返回失败结果
     */
    @PostMapping("/submit")
    public ResponseResult submitResume(@RequestBody ResumeAndJob resumeAndJob) {
        if (resumeAndJobService.submitResume(resumeAndJob)) {
            return ResponseResult.success();
        } else {
            return ResponseResult.fail("提交失败");
        }
    }

    /**
     * 审核通过
     *
     * @param dto 包含通过审核的简历ID和职位ID
     * @return 审核成功返回成功结果，否则返回失败结果
     */
    @PostMapping("/pass")
    public ResponseResult pass(@RequestBody PassAndInterviewNotificationDTO dto) {
        if (resumeAndJobService.pass(new ResumeAndJob(dto.getResumeId(), dto.getJobId(), 1))) {
            interviewNotification.alarm(dto);
            return ResponseResult.success();
        } else {
            return ResponseResult.fail("审核失败");
        }
    }

    /**
     * 审核不通过
     *
     * @param resumeAndJob 包含未通过审核的简历和职位信息
     * @return 审核操作成功返回成功结果，否则返回失败结果
     */
    @PostMapping("/no_pass")
    public ResponseResult notPass(@RequestBody ResumeAndJob resumeAndJob) {
        if (resumeAndJobService.notPass(resumeAndJob)) {
            return ResponseResult.success();
        } else {
            return ResponseResult.fail("审核失败");
        }
    }

    /**
     * 根据职位ID获取简历列表
     *
     * @param jobId 职位的ID
     * @return 返回根据职位ID获取的简历列表
     */
    @GetMapping("/list/resume")
    public ResponseResult getResumeByJobId(Long jobId) {
        return ResponseResult.success(resumeAndJobService.getResumeByJobId(jobId));
    }

    /**
     * 获取待审核的简历详情
     *
     * @param tokenStr 请求头中的授权令牌
     * @return 返回待审核简历的详情
     */
    @GetMapping("/list/check_resume")
    public ResponseResult<CheckResumeVO> getCheckResumeVO(@RequestHeader("Authorization") String tokenStr) {
        Long enterpriseId = token.getUidByToken(tokenStr);
        return ResponseResult.success(resumeAndJobService.getCheckResumeVO(enterpriseId));
    }
}
